//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    // 上拉加载
    allGoodsData: [],
    pageIndex: 1,
    state: "",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.GetMoreNewProduct();
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.GetMoreNewProduct();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  // 
  GetMoreNewProduct: function() {
    wx.showLoading({
      title: '加载中',
      icon: 'success',
      duration: 2000
    })
    var that = this;
    var allGoodsData = this.data.allGoodsData;
    var pageIndex = this.data.pageIndex;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=&Type=1&PageSize=10&PageIndex=" + pageIndex),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          allGoodsData.push(json[i])
        }
        that.setData({
          allGoodsData: allGoodsData,
        })
        console.log(allGoodsData);
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        wx.hideLoading();
    
      }
    })
  },
  // 
})